home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / COMM.SWG / 0055_RS-232 to serial port.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  4KB  |  85 lines

  1. {
  2. GV>If it's high you may not be able to rely upon TP's Read/Write
  3.   >procedures.  If it's really high you may need to let an ISR do
  4.   >the job of i/o buffering.
  5. JS> Oh! God. I hope not. I'm not ready for TSRs. Oops, you didn't
  6.   > say TSR, you said ISR.
  7.  
  8.  Have no fear... I wouldn't lead you into waters that you couldn't
  9.  navigate through on your own!  But, how about getting familiar
  10.  with using the CPU Registers, and the BIOS, via TP?  [FYI: ISRs
  11.  (interrupt service routines) can be run attached to the DOS, in
  12.  the form of TSRs or device drivers, or temporarily as part of an
  13.  application.]
  14.  
  15.  9600 bits-per-second (bps) is about as fast as vanilla DOS can
  16.  go with the serial ports. To be safe from loosing data, your
  17.  i/o should be buffered by a hardware-driven ISR. But, as you say,
  18.  writing & interfacing to a TSR/ISR can be a bit heady, especially
  19.  when all you need is the odd text string.
  20.  
  21.  I'd recommend that you use a "FOSSIL driver," such as X00.  It
  22.  gets loaded as a TSR in your AUTOEXEC.BAT file, or as a device
  23.  driver in CONFIG.SYS, and intercepts the BIOS serial interrupt
  24.  to provide data capture & buffering. X00 is solid, and is used by
  25.  many BBS SysOps. It's available for download at most local BBSs.
  26.  It can be run under DOS, Windows, or DESQview.
  27.  
  28.  You can use TP's INTR() function to talk with the serial port, or
  29.  use one of the existing TP source code libraries that can also be
  30.  found on BBSs. The X00 archive comes with an example of using X00
  31.  with TP, and even has a ready-to-link TPX00.OBJ file.
  32.  
  33.  The X00 commands are a superset of BIOS interrupt 14H commands, so
  34.  you may already have a book which documents how to use it -- though
  35.  you'll probably want to know how to set the buffer size, etc.  X00
  36.  comes with thorough documentation.
  37.  
  38. JS> Although it is 9600 baud, a data string is sent only every second
  39.   > or longer. One data string BTW consists of a concentration and a
  40.   > date/time in a format something like this:
  41.   >        350.0ppm 12:42:37 Jun 13'94
  42.   > so you can see that the port is idle most of the time. I know
  43.   > that might not matter.
  44.  
  45.  This should be easy enough to handle.  Here's an example snippet of
  46.  using X00 with TP (from the X00 archive file) ...
  47. }
  48.  
  49.   CONST   Buffer_Size = 1024;
  50.  
  51.   VAR     Regs : REGISTERS;
  52.           Input_Buffer : ARRAY [1..Buffer_Size] OF BYTE;
  53.  
  54.   PROCEDURE Bypass; EXTERNAL;
  55.   PROCEDURE TPX00( VAR Regs : REGISTERS ); EXTERNAL; {$L TPX00}
  56.  
  57.   BEGIN
  58.   { Check for active FOSSIL }
  59.   Regs.AH := $04;  Regs.BX := 0;  Regs.DX := $00FF;
  60.   { INTR( $14, Regs ); is replaced with }
  61.   TPX00( Regs );
  62.   FOSSIL_Active := Regs.AX = $1954;
  63.  
  64.   IF FOSSIL_Active THEN BEGIN
  65.     { Open FOSSIL port 0, COM1 }
  66.     Regs.AH := $04;  Regs.BX := 0;  Regs.DX := $0000;
  67.     { INTR( $14, Regs ); is replaced with }
  68.     TPX00( Regs );
  69.     { Do a block read from the FOSSIL input buffer for COM1 }
  70.     Regs.AH := $18;                  { Block read func code }
  71.     Regs.DI := OFS( Input_Buffer );  { Input buffer offset  to DI }
  72.     Regs.ES := SEG( Input_Buffer );  { Input buffer segment to ES }
  73.     Regs.CX := Buffer_Size;          { Max bytes to read to CX }
  74.     Regs.DX := 0;                    { Data from COM1 }
  75.     { INTR( $14, Regs ); is replaced with }
  76.     TPX00( Regs );
  77.     { Upon return, Regs.AX will contain the number of bytes that X00 }
  78.     { placed into Input_Buffer. }
  79.   END;
  80. {
  81.  If this looks too "scary," you could try one of the existing TP
  82.  FOSSIL interface libraries, which would provide a higher-level of
  83.  functions (eg. GetComChar, etc).
  84. }
  85.